/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       directionallight.cpp
 * Author:     karooolek
 * Created on: 2009-03-27
 *
 **********************************************************************************************************************/

#include "directionallight.h"

namespace mGameEngine
{
namespace Graphics
{

DirectionalLight::DirectionalLight() :
    AmbientLight(),
    _direction(1.0f, 0.0f, 0.0f), _diffuse(), _specular()
{
}

DirectionalLight::DirectionalLight(const Color &ambient, const Color &diffuse,
        const Color &specular, const Vector3 &direction) :
    AmbientLight(ambient),
    _direction(direction),
    _diffuse(diffuse), _specular(specular)
{
}

DirectionalLight::~DirectionalLight()
{
}

void DirectionalLight::set(uint l) const
{
    if(!_enabled)
    {
        return;
    }

    l += GL_LIGHT0;
    glLightfv(l, GL_AMBIENT, _ambient);
    glLightfv(l, GL_DIFFUSE, _diffuse);
    glLightfv(l, GL_SPECULAR, _specular);
    glLightf(l, GL_CONSTANT_ATTENUATION, 1.0f);
    glLightf(l, GL_LINEAR_ATTENUATION, 0.0f);
    glLightf(l, GL_QUADRATIC_ATTENUATION, 0.0f);
    glLightfv(l, GL_POSITION, Vector4(-9999999.9f * _direction, 1.0));

    // TODO FIX sthg is terribly wrong.. and doesn't work on some computers
    glLightf(l, GL_SPOT_CUTOFF, 0.0f);
    glLightf(l, GL_SPOT_EXPONENT, 0.0f);
}

}
}

